package admin

import (
	"exercise/application/yiran/app/libs"
	"exercise/application/yiran/app/request/adminRequest"
	"exercise/application/yiran/app/service/admin"
	"github.com/gin-gonic/gin"
)

type attachmentController struct {
}

// UncompletedTasks 校验是否存在未完成的任务
func (a *attachmentController) UncompletedTasks(ctx *gin.Context) {
	err := admin.NewAttachmentService().UncompletedTasks(ctx)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "存在未完成的任务,直接运行即可")
}

// CheckNotice 校验文件夹数量
func (a *attachmentController) CheckNotice(ctx *gin.Context) {
	request := new(adminRequest.CheckNoticeRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	ret, err := admin.NewAttachmentService().CheckNotice(request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	libs.Success(ctx, ret)
}

// UnZipNotice 解压
func (a *attachmentController) UnZipNotice(ctx *gin.Context) {
	request := new(adminRequest.UnZipNoticeRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	err = admin.NewAttachmentService().UnZipNotice(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	libs.OkToast(ctx, "解压成功")
}

// SaveNotice 保存
func (a *attachmentController) SaveNotice(ctx *gin.Context) {
	request := new(adminRequest.SaveNoticeRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	ret, err := admin.NewAttachmentService().SaveNotice(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	libs.Success(ctx, ret)
}

// ZipNotice 分页压缩
func (a *attachmentController) ZipNotice(ctx *gin.Context) {
	err := admin.NewAttachmentService().ZipNotice(ctx)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "压缩成功")
}

func (a *attachmentController) CreateNotice(ctx *gin.Context) {
	list, err := admin.NewAttachmentService().CreateNotice(ctx)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, list)
}

func NewAttachmentController() *attachmentController {
	return &attachmentController{}
}
